Skip to contentSkip to conversation

Build and run unittests with mingw in Github actions

PATCH In review Arne Schwabe 3 participants 24 messages Feb 8, 2023 – Feb 14, 2023 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

cover Build and run unittests with mingw in Github actions

This patch also includes the previous patches from Sevla to make the dependency from these patches clear. Patch 0/3 can be squashed into 2/5 as it is only a minor fixup of that patch.

The Github actions could probably made a little bit nicer, eg by static compiling and requiring copying less dlls but since these binaries are not meant to be distributed, I don't think it is an issue.

Arne Schwabe (3):
Do not run check_engine test when crosscompiling Add missing stdint.h includes in unit tests files Add building unit tests with mingw to github actions

Selva Nair (2):
Conditionally add subdir-objects option to automake Build unit tests in mingw Windows build

 .github/workflows/build.yaml              | 110 +++++++++++++++++++++-
 configure.ac                              |  17 +++-
 tests/Makefile.am                         |   3 +
 tests/unit_tests/engine-key/Makefile.am   |   2 +
 tests/unit_tests/example_test/Makefile.am |   2 +
 tests/unit_tests/example_test/test.c      |   1 +
 tests/unit_tests/example_test/test2.c     |   1 +
 tests/unit_tests/openvpn/Makefile.am      |  28 +++++-
 tests/unit_tests/openvpn/mock_msg.c       |   1 +
 9 files changed, 157 insertions(+), 8 deletions(-)
Signature · 1 line
2.37.1 (Apple Git-137.1)
#1 lore raw

PATCH 1/5 Conditionally add subdir-objects option to automake

From: Selva Nair <[email protected]...>

- Eliminates repeated warnings such as
warning: source file '$(openvpn_srcdir)/env_set.c' is in a subdirectory, but option 'subdir-objects' is disabled
- Enabled only for automake >= 1.16 as older versions have a buggy implementation of this option

Main side effect of this option is that object files like openvpnserv-blockdns.o are now created in src/openvpn where block-dns.c resides instead of in src/openvpnserv. Same for object files for sources from $(openvpn_srcdir) compiled into test executables.

See also past discussion on this topic:
https://www.mail-archive.com/[email protected]/msg00013.html

---
 configure.ac | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
configure.ac +14 -1
index 915000870..95d795c33 100644
@@ -54,9 +54,22 @@ m4_define([serial_tests], [
                 awk '{split ($NF,a,"."); if (a[1] == 1 && a[2] >= 12) { print "serial-tests" }}'
     ])
 ])
+
+dnl Automake 1.14+ warns if sources are in sub-directories but subdir-objects
+dnl options is not enabled. However, automake before 1.15a has a bug that causes
+dnl variable expansion to fail in foo_SOURCES when this option is used.
+dnl As most of our build systems are now likely to use automake 1.16+ add a
+dnl work around to conditionally add subdir-objects option.
+m4_define([subdir_objects], [
+    m4_esyscmd([automake --version |
+                head -1 |
+                awk '{split ($NF,a,"."); if (a[1] == 1 && a[2] >= 16) { print "subdir-objects" }}'
+    ])
+])
+
 # This foreign option prevents autoreconf from overriding our COPYING and
 # INSTALL targets:
-AM_INIT_AUTOMAKE(foreign serial_tests 1.9) dnl NB: Do not [quote] this parameter.
+AM_INIT_AUTOMAKE(foreign serial_tests subdir_objects 1.9) dnl NB: Do not [quote] this parameter.
 AC_CANONICAL_HOST
 AC_USE_SYSTEM_EXTENSIONS
 
Signature · 1 line
2.37.1 (Apple Git-137.1)
#2 lore raw

Re: [Openvpn-devel] [PATCH 1/5] Conditionally add subdir-objects option to automake

Quoted 16 lines · Arne Schwabe

From: Selva Nair <[email protected]...>

- Eliminates repeated warnings such as
warning: source file '$(openvpn_srcdir)/env_set.c' is in a subdirectory, but option 'subdir-objects' is disabled
- Enabled only for automake >= 1.16 as older versions have a buggy implementation
of this option

Main side effect of this option is that object files like openvpnserv-blockdns.o
are now created in src/openvpn where block-dns.c resides instead of in src/openvpnserv. Same for object files for sources from $(openvpn_srcdir) compiled
into test executables.

Quoted 7 lines

See also past discussion on this topic:

https://www.mail-archive.com/[email protected]/msg00013.html

I'm a bit confused here -- it seems you have made some edits to my patch (signed-off), but not clear what has changed.

As for my original 3/3, I will add your fix for engine-test and submit as v3 -- thanks for working on this.

I've no idea why libtool adds that wrong line break in its wrapper script on OSX.

Selva

#3 lore raw

Re: [Openvpn-devel] [PATCH 1/5] Conditionally add subdir-objects option to automake

Am 08.02.2023 um 01:40 schrieb Selva Nair:

Quoted 21 lines · Arne Schwabe

From: Selva Nair <[email protected]...>

- Eliminates repeated warnings such as
  warning: source file '$(openvpn_srcdir)/env_set.c' is in a subdirectory,
  but option 'subdir-objects' is disabled
- Enabled only for automake >= 1.16 as older versions have a buggy implementation
  of this option

Main side effect of this option is that object files like openvpnserv-blockdns.o
are now created in src/openvpn where block-dns.c resides instead of in src/openvpnserv. Same for object files for sources from $(openvpn_srcdir) compiled
into test executables.

Quoted 8 lines

See also past discussion on this topic:
https://www.mail-archive.com/[email protected]/msg00013.html

I'm a bit confused here -- it seems you have made some edits to my patch (signed-off), but not clear what has changed.

I didn't make changes as I said in the cover letter. The signoff automatically happens since with patch sending.

Arne

#4 lore raw

PATCH v2 2/5 Build unit tests in mingw Windows build

In reply to Arne Schwabe

From: Selva Nair <[email protected]...>

- Minor changes to the build system to include some dependencies for Windows build

- test_tls_crypt not built as it will pull in win32.c and its dependencies

- If cross-compiling, "make check" will only build the tests but not run any. Copy to Windows and run manually. Executables are in <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on cmocka.dll in addition to openssl libs that some tests link to.

Building with mingw on Windows should run the tests (untested).

v2: networking_testdriver was mistakenly enabled to run, while originally it was only set to build. Corrected.

---
 configure.ac                              |  2 ++
 tests/Makefile.am                         |  3 +++
 tests/unit_tests/example_test/Makefile.am |  2 ++
 tests/unit_tests/openvpn/Makefile.am      | 28 +++++++++++++++++++----
 4 files changed, 30 insertions(+), 5 deletions(-)
configure.ac +2 -0
index 95d795c33..66ba6f38d 100644
@@ -364,6 +364,8 @@ case "$host" in
 		;;
 esac
 
+AM_CONDITIONAL([CROSS_COMPILING], test "${cross_compiling}" = "yes")
+
 PKG_PROG_PKG_CONFIG
 AC_PROG_CPP
 AC_PROG_INSTALL
tests/Makefile.am +3 -0
index 87dd7e17b..175a4eef6 100644
@@ -14,10 +14,13 @@ MAINTAINERCLEANFILES = \
 
 SUBDIRS = unit_tests
 
+if !WIN32
 test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh
+test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh t_connection.sh
 if HAVE_SITNL
 test_scripts += t_net.sh
 endif
+endif
 
 TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)"
 TESTS = $(test_scripts)
tests/unit_tests/example_test/Makefile.am +2 -0
index 04a5ad356..24eb0ba18 100644
@@ -2,7 +2,9 @@ AUTOMAKE_OPTIONS = foreign
 
 check_PROGRAMS = example_testdriver example2_testdriver
 
+if !CROSS_COMPILING
 TESTS = $(check_PROGRAMS)
+endif
 
 example_testdriver_CFLAGS  = @TEST_CFLAGS@
 example_testdriver_LDFLAGS = @TEST_LDFLAGS@
tests/unit_tests/openvpn/Makefile.am +23 -5
index 7720a85db..8d2386e08 100644
@@ -7,14 +7,22 @@ test_binaries += argv_testdriver buffer_testdriver
 endif
 
 test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \
-    pkt_testdriver
+	pkt_testdriver
 if HAVE_LD_WRAP_SUPPORT
+if !WIN32
 test_binaries += tls_crypt_testdriver
 endif
+endif
 
 test_binaries += provider_testdriver
 
+if WIN32
+LDADD = -lws2_32
+endif
+
+if !CROSS_COMPILING
 TESTS = $(test_binaries)
+endif
 check_PROGRAMS = $(test_binaries)
 
 if HAVE_SITNL
@@ -31,12 +39,14 @@ argv_testdriver_SOURCES = test_argv.c mock_msg.c mock_msg.h \
 	mock_get_random.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/buffer.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/argv.c
 
 buffer_testdriver_CFLAGS  = @TEST_CFLAGS@ -I$(openvpn_srcdir) -I$(compat_srcdir)
 buffer_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(openvpn_srcdir) -Wl,--wrap=parse_line
 buffer_testdriver_SOURCES = test_buffer.c mock_msg.c mock_msg.h \
 	mock_get_random.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c
 
 crypto_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -51,6 +61,7 @@ crypto_testdriver_SOURCES = test_crypto.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/mtu.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/mss.c
 
 packet_id_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -63,14 +74,14 @@ packet_id_testdriver_SOURCES = test_packet_id.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/reliable.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/session_id.c
 
-
 pkt_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir)
 pkt_testdriver_LDFLAGS = @TEST_LDFLAGS@
 pkt_testdriver_SOURCES = test_pkt.c mock_msg.c mock_msg.h \
-$(openvpn_srcdir)/argv.c \
+	$(openvpn_srcdir)/argv.c \
 	$(openvpn_srcdir)/base64.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/crypto.c \
@@ -84,9 +95,10 @@ $(openvpn_srcdir)/argv.c \
 	$(openvpn_srcdir)/run_command.c \
 	$(openvpn_srcdir)/session_id.c \
 	$(openvpn_srcdir)/ssl_pkt.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/tls_crypt.c
 
-
+if !WIN32
 tls_crypt_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir)
 tls_crypt_testdriver_LDFLAGS = @TEST_LDFLAGS@ \
@@ -106,6 +118,7 @@ tls_crypt_testdriver_SOURCES = test_tls_crypt.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/run_command.c
+endif
 
 if HAVE_SITNL
 networking_testdriver_CFLAGS = @TEST_CFLAGS@ \
@@ -136,6 +149,7 @@ provider_testdriver_SOURCES = test_provider.c mock_msg.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/base64.c \
 	mock_get_random.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c
 
 auth_token_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -152,6 +166,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \
 	$(openvpn_srcdir)/otime.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/base64.c
 
 
@@ -169,6 +184,8 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \
 	$(openvpn_srcdir)/otime.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
+	$(openvpn_srcdir)/win32-util.c \
+	$(compat_srcdir)/compat-strsep.c \
 	$(openvpn_srcdir)/ssl_util.c
 
 misc_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -177,8 +194,9 @@ misc_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
 
 misc_testdriver_SOURCES = test_misc.c mock_msg.c \
-    mock_get_random.c \
+	mock_get_random.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/options_util.c \
 	$(openvpn_srcdir)/ssl_util.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c
Signature · 1 line
2.37.1 (Apple Git-137.1)
#5 lore raw

PATCH v3 2/3 Build unit tests in mingw Windows build

From: Selva Nair <[email protected]...>

- Minor changes to the build system to include some dependencies for Windows build

- test_tls_crypt not built as it will pull in win32.c and its dependencies

- If cross-compiling, "make check" will only build the tests but not run any. Copy to Windows and run manually. Executables are in <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on cmocka.dll in addition to openssl libs that some tests link to.

Building with mingw on Windows should run the tests (untested).

v2: networking_testdriver was mistakenly enabled to run, while originally it was only set to build. Corrected.

v3: exclude check_engine_keys.sh when cross-compiling As suggested by Arne Schwabe <[email protected]...>

---
 configure.ac                              |  2 ++
 tests/Makefile.am                         |  2 ++
 tests/unit_tests/engine-key/Makefile.am   |  2 ++
 tests/unit_tests/example_test/Makefile.am |  2 ++
 tests/unit_tests/openvpn/Makefile.am      | 28 +++++++++++++++++++----
 5 files changed, 31 insertions(+), 5 deletions(-)
configure.ac +2 -0
index 95d795c3..66ba6f38 100644
@@ -364,6 +364,8 @@ case "$host" in
 		;;
 esac
 
+AM_CONDITIONAL([CROSS_COMPILING], test "${cross_compiling}" = "yes")
+
 PKG_PROG_PKG_CONFIG
 AC_PROG_CPP
 AC_PROG_INSTALL
tests/Makefile.am +2 -0
index 87dd7e17..a46f2573 100644
@@ -14,10 +14,12 @@ MAINTAINERCLEANFILES = \
 
 SUBDIRS = unit_tests
 
+if !WIN32
 test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh
 if HAVE_SITNL
 test_scripts += t_net.sh
 endif
+endif
 
 TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)"
 TESTS = $(test_scripts)
tests/unit_tests/engine-key/Makefile.am +2 -0
index 24622251..0c288857 100644
@@ -12,7 +12,9 @@ TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
 	top_srcdir="$(top_srcdir)"; \
 	export srcdir builddir top_builddir top_srcdir;
 
+if !CROSS_COMPILING
 TESTS = check_engine_keys.sh
+endif
 check_engine_keys.sh: $(conffiles)
 
 CLEANFILES = \
tests/unit_tests/example_test/Makefile.am +2 -0
index 04a5ad35..24eb0ba1 100644
@@ -2,7 +2,9 @@ AUTOMAKE_OPTIONS = foreign
 
 check_PROGRAMS = example_testdriver example2_testdriver
 
+if !CROSS_COMPILING
 TESTS = $(check_PROGRAMS)
+endif
 
 example_testdriver_CFLAGS  = @TEST_CFLAGS@
 example_testdriver_LDFLAGS = @TEST_LDFLAGS@
tests/unit_tests/openvpn/Makefile.am +23 -5
index 7720a85d..8d2386e0 100644
@@ -7,14 +7,22 @@ test_binaries += argv_testdriver buffer_testdriver
 endif
 
 test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver \
-    pkt_testdriver
+	pkt_testdriver
 if HAVE_LD_WRAP_SUPPORT
+if !WIN32
 test_binaries += tls_crypt_testdriver
 endif
+endif
 
 test_binaries += provider_testdriver
 
+if WIN32
+LDADD = -lws2_32
+endif
+
+if !CROSS_COMPILING
 TESTS = $(test_binaries)
+endif
 check_PROGRAMS = $(test_binaries)
 
 if HAVE_SITNL
@@ -31,12 +39,14 @@ argv_testdriver_SOURCES = test_argv.c mock_msg.c mock_msg.h \
 	mock_get_random.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/buffer.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/argv.c
 
 buffer_testdriver_CFLAGS  = @TEST_CFLAGS@ -I$(openvpn_srcdir) -I$(compat_srcdir)
 buffer_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(openvpn_srcdir) -Wl,--wrap=parse_line
 buffer_testdriver_SOURCES = test_buffer.c mock_msg.c mock_msg.h \
 	mock_get_random.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c
 
 crypto_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -51,6 +61,7 @@ crypto_testdriver_SOURCES = test_crypto.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/mtu.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/mss.c
 
 packet_id_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -63,14 +74,14 @@ packet_id_testdriver_SOURCES = test_packet_id.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/reliable.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/session_id.c
 
-
 pkt_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir)
 pkt_testdriver_LDFLAGS = @TEST_LDFLAGS@
 pkt_testdriver_SOURCES = test_pkt.c mock_msg.c mock_msg.h \
-$(openvpn_srcdir)/argv.c \
+	$(openvpn_srcdir)/argv.c \
 	$(openvpn_srcdir)/base64.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/crypto.c \
@@ -84,9 +95,10 @@ $(openvpn_srcdir)/argv.c \
 	$(openvpn_srcdir)/run_command.c \
 	$(openvpn_srcdir)/session_id.c \
 	$(openvpn_srcdir)/ssl_pkt.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/tls_crypt.c
 
-
+if !WIN32
 tls_crypt_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir)
 tls_crypt_testdriver_LDFLAGS = @TEST_LDFLAGS@ \
@@ -106,6 +118,7 @@ tls_crypt_testdriver_SOURCES = test_tls_crypt.c mock_msg.c mock_msg.h \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/run_command.c
+endif
 
 if HAVE_SITNL
 networking_testdriver_CFLAGS = @TEST_CFLAGS@ \
@@ -136,6 +149,7 @@ provider_testdriver_SOURCES = test_provider.c mock_msg.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/base64.c \
 	mock_get_random.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c
 
 auth_token_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -152,6 +166,7 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \
 	$(openvpn_srcdir)/otime.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/base64.c
 
 
@@ -169,6 +184,8 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \
 	$(openvpn_srcdir)/otime.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
+	$(openvpn_srcdir)/win32-util.c \
+	$(compat_srcdir)/compat-strsep.c \
 	$(openvpn_srcdir)/ssl_util.c
 
 misc_testdriver_CFLAGS  = @TEST_CFLAGS@ \
@@ -177,8 +194,9 @@ misc_testdriver_CFLAGS  = @TEST_CFLAGS@ \
 misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
 
 misc_testdriver_SOURCES = test_misc.c mock_msg.c \
-    mock_get_random.c \
+	mock_get_random.c \
 	$(openvpn_srcdir)/buffer.c \
 	$(openvpn_srcdir)/options_util.c \
 	$(openvpn_srcdir)/ssl_util.c \
+	$(openvpn_srcdir)/win32-util.c \
 	$(openvpn_srcdir)/platform.c
Signature · 1 line
2.34.1
author Acked-by on v3 2/3
#6 lore raw

Re: [Openvpn-devel] [PATCH v3 2/3] Build unit tests in mingw Windows build

Am 08.02.23 um 01:59 schrieb [email protected]...:

Quoted 13 lines

From: Selva Nair <[email protected]...>

- Minor changes to the build system to include some dependencies for Windows build

- test_tls_crypt not built as it will pull in win32.c and its dependencies

- If cross-compiling, "make check" will only build the tests but not run any. Copy to Windows and run manually. Executables are in <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on cmocka.dll in addition to openssl libs that some tests link to.

Quoted 7 lines

Building with mingw on Windows should run the tests (untested).

v2: networking_testdriver was mistakenly enabled to run, while originally it was only set to build. Corrected.

v3: exclude check_engine_keys.sh when cross-compiling As suggested by Arne Schwabe <[email protected]...>

Arne

#7 lore raw

Re: [Openvpn-devel] [PATCH v3 2/3] Build unit tests in mingw Windows build

In reply to [email protected]...

Hi,

Quoted 5 lines · On Tue, Feb 07, 2023 at 07:59:25PM -0500, [email protected]... wrote:

From: Selva Nair <[email protected]...>

- Minor changes to the build system to include some dependencies for Windows build

Quoted 7 lines

- test_tls_crypt not built as it will pull in win32.c and its dependencies

- If cross-compiling, "make check" will only build the tests but not run any. Copy to Windows and run manually. Executables are in <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on cmocka.dll in addition to openssl libs that some tests link to.

I am something wrong, or I'm missing some bits.

I took this patch, on top of commit e80720ef939 ("top of master as of now"). MinGW on Ubuntu. "autoreconf -iv", make clean, then make && make check.

make check claims

make[4]: Entering directory '/home/gert/mingw/openvpn.git/tests'
==================
All 0 tests passed
==================

... but it seems to have done... nothing?

[email protected]...:~/mingw/openvpn.git$ ls -l tests/unit_test/openvpn/.libs
ls: cannot access 'tests/unit_test/openvpn/.libs': No such file or directory

... given argv_testdriver exists, I should find "something" with argv*.o* here...

[email protected]...:~/mingw/openvpn.git$ find . -name "*argv*o"
./tests/unit_tests/openvpn/.deps/argv_testdriver-mock_get_random.Po
./tests/unit_tests/openvpn/.deps/tls_crypt_testdriver-argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-test_argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-mock_msg.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-platform.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-buffer.Po
./tests/unit_tests/openvpn/.deps/pkt_testdriver-argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-argv.Po
./src/openvpn/.deps/tls_crypt_testdriver-argv.Po
./src/openvpn/.deps/argv.Po
./src/openvpn/.deps/argv_testdriver-win32-util.Po
./src/openvpn/.deps/argv_testdriver-platform.Po
./src/openvpn/.deps/argv_testdriver-buffer.Po
./src/openvpn/.deps/pkt_testdriver-argv.Po
./src/openvpn/.deps/argv_testdriver-argv.Po
./src/openvpn/argv.o

... so it seems as if it did the "make depend" dance for the unit_tests, but then didn't compile anything for real.

Did I apply stuff in the wrong order? Do I need to more forcefully clean my build tree?

slightly puzzled...

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#8 lore raw

Re: [Openvpn-devel] [PATCH v3 2/3] Build unit tests in mingw Windows build

Quoted 22 lines · Gert Doering

Hi,

Quoted 5 lines · On Tue, Feb 07, 2023 at 07:59:25PM -0500, [email protected]... wrote:

From: Selva Nair <[email protected]...>

- Minor changes to the build system to include some dependencies for Windows build

Quoted 7 lines

- test_tls_crypt not built as it will pull in win32.c and its dependencies

- If cross-compiling, "make check" will only build the tests but not run any. Copy to Windows and run manually. Executables are in <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on cmocka.dll in addition to openssl libs that some tests link to.

I am something wrong, or I'm missing some bits.

I took this patch, on top of commit e80720ef939 ("top of master as of now"). MinGW on Ubuntu. "autoreconf -iv", make clean, then make && make check.

Quoted 9 lines

make check claims

make[4]: Entering directory '/home/gert/mingw/openvpn.git/tests'
==================
All 0 tests passed
==================

... but it seems to have done... nothing?

My patch only enables to build the tests while cross-compiling but disables running them. As the executables are not native, you have to manually copy them to Windows and run there.

With the next patch from Arne, GHA actions will copy it automagically to Windows and run there. But that works only for github actions.

Selva

#9 lore raw

Re: [Openvpn-devel] [PATCH v3 2/3] Build unit tests in mingw Windows build

In reply to Gert Doering

Hi

Quoted 56 lines · Gert Doering

Hi,

Quoted 5 lines · On Tue, Feb 07, 2023 at 07:59:25PM -0500, [email protected]... wrote:

From: Selva Nair <[email protected]...>

- Minor changes to the build system to include some dependencies for Windows build

Quoted 7 lines

- test_tls_crypt not built as it will pull in win32.c and its dependencies

- If cross-compiling, "make check" will only build the tests but not run any. Copy to Windows and run manually. Executables are in <buid-dir>/tests/unit_tests/openvpn/.libs/ and these depend on cmocka.dll in addition to openssl libs that some tests link to.

I am something wrong, or I'm missing some bits.

I took this patch, on top of commit e80720ef939 ("top of master as of now"). MinGW on Ubuntu. "autoreconf -iv", make clean, then make && make check.

make check claims

make[4]: Entering directory '/home/gert/mingw/openvpn.git/tests'
==================
All 0 tests passed
==================

... but it seems to have done... nothing?

[email protected]...:~/mingw/openvpn.git$ ls -l tests/unit_test/openvpn/.libs
ls: cannot access 'tests/unit_test/openvpn/.libs': No such file or
directory

... given argv_testdriver exists, I should find "something" with argv*.o* here...

[email protected]...:~/mingw/openvpn.git$ find . -name "*argv*o"
./tests/unit_tests/openvpn/.deps/argv_testdriver-mock_get_random.Po
./tests/unit_tests/openvpn/.deps/tls_crypt_testdriver-argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-test_argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-mock_msg.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-platform.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-buffer.Po
./tests/unit_tests/openvpn/.deps/pkt_testdriver-argv.Po
./tests/unit_tests/openvpn/.deps/argv_testdriver-argv.Po
./src/openvpn/.deps/tls_crypt_testdriver-argv.Po
./src/openvpn/.deps/argv.Po
./src/openvpn/.deps/argv_testdriver-win32-util.Po
./src/openvpn/.deps/argv_testdriver-platform.Po
./src/openvpn/.deps/argv_testdriver-buffer.Po
./src/openvpn/.deps/pkt_testdriver-argv.Po
./src/openvpn/.deps/argv_testdriver-argv.Po
./src/openvpn/argv.o
Quoted 7 lines

... so it seems as if it did the "make depend" dance for the unit_tests, but then didn't compile anything for real.

Did I apply stuff in the wrong order? Do I need to more forcefully clean my build tree?

Ignore the previous email -- (I behaved as if I can't read more than a pageful).

Looks like unit-tests are not enabled during configure. For that, cmocka should be available in the search path or set using CMOCKA_LIBS and CMOCKA_INCLUDES.

It took a while for me to figure out how to cross-compile cmocka using cmake and mingw on Linux. Finally what worked was pretty simple:

git clone https://github.com/clibs/cmocka.git
cd cmocka
checkout cmocka-1.1.5
mkdir build
cd build
cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc \
-DCMAKE_INSTALL_PREFIX=$HOME/mingw-cmocka/ -S .. -B .
make install

Selva

#10 lore raw

Re: [Openvpn-devel] [PATCH v3 2/3] Build unit tests in mingw Windows build

Hi,

Quoted 2 lines · Selva Nair

Ignore the previous email -- (I behaved as if I can't read more than a pageful).

:-)

Quoted 3 lines

Looks like unit-tests are not enabled during configure. For that, cmocka should be available in the search path or set using CMOCKA_LIBS and CMOCKA_INCLUDES.

Yes, that's the conclusion I arrived at, after I sent yesterday's mail and went to bed - "oh no, it can't do anything, there is no cmocka in that cross-compile environment". But I didn't want to get up again just to send that followup mail ;-)

Quoted 13 lines

It took a while for me to figure out how to cross-compile cmocka using cmake and mingw on Linux. Finally what worked was pretty simple:

git clone https://github.com/clibs/cmocka.git
cd cmocka
checkout cmocka-1.1.5
mkdir build
cd build
cmake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc \
-DCMAKE_INSTALL_PREFIX=$HOME/mingw-cmocka/ -S .. -B .
make install

This would have been my next question "how do I build this?" :-)

... adapted to my build environment...

-- Installing: /home/gert/mingw/opt/include/cmocka.h -- Installing: /home/gert/mingw/opt/bin/cmocka.dll

... then returning to openvpn & re-running configure, it will still not find it :-(

checking for CMOCKA... no
configure: WARNING: cmocka.pc not found on the system. Unit tests disabled

... so, configure CMOCKA_CFLAGS/CMOCKA_LIBS it is...

checking for CMOCKA... yes

... but then trying to build the test drivers fails, and from the looks of it, it's finding but not utilizing the cmocka lib...

/bin/bash ../../../libtool --tag=CC --mode=link i686-w64-mingw32-gcc -I/home/gert/mingw/opt/include -I/home/gert/mingw/opt/include -I../../../include -I/home/gert/mingw/opt/include -Wall -Wno-stringop-truncation -I/home/gert/mingw/opt/include -std=c99 -L/home/gert/mingw/lib -L/home/gert/mingw/opt/lib64 -lssl -lcrypto -L/home/gert/mingw/opt/lib -llzo2 -L/home/gert/mingw/opt/lib -lcmocka -L/home/gert/mingw/opt/lib -o example_testdriver.exe example_testdriver-test.o
libtool: link: i686-w64-mingw32-gcc -I/home/gert/mingw/opt/include -I/home/gert/mingw/opt/include -I../../../include -I/home/gert/mingw/opt/include -Wall -Wno-stringop-truncation -I/home/gert/mingw/opt/include -std=c99 -o .libs/example_testdriver.exe example_testdriver-test.o -L/home/gert/mingw/lib -L/home/gert/mingw/opt/lib64 -lssl -lcrypto -L/home/gert/mingw/opt/lib /home/gert/mingw/opt/lib/liblzo2.a -lwinmm -lcmocka /usr/bin/i686-w64-mingw32-ld: example_testdriver-test.o:test.c:(.text+0x89): undefined reference to `_assert_int_equal'
/usr/bin/i686-w64-mingw32-ld: example_testdriver-test.o:test.c:(.text+0xc6): undefined reference to `_assert_int_equal'
/usr/bin/i686-w64-mingw32-ld: example_testdriver-test.o:test.c:(.text+0x153): undefined reference to `_cmocka_run_group_tests'
collect2: error: ld returned 1 exit status
make[5]: *** [Makefile:461: example_testdriver.exe] Error 1

... tried various permutations of "-L$path -lcmocka", putting the actual path to "libcmocka.dll.a" on the link/libtool command line, but the error never changes...

*scratch head*

Need to debug this more tonight...

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#11 lore raw

Re: [Openvpn-devel] [PATCH v3 2/3] Build unit tests in mingw Windows build

Hi,

Quoted 3 lines · Gert Doering

/bin/bash ../../../libtool --tag=CC --mode=link i686-w64-mingw32-gcc

This is a 32 bit build which I never tried. Maybe cmocka is not built for 32 bit?

Quoted 15 lines
(quoted diff) +0 -6
-I/home/gert/mingw/opt/include  -I/home/gert/mingw/opt/include
-I../../../include -I/home/gert/mingw/opt/include -Wall
-Wno-stringop-truncation -I/home/gert/mingw/opt/include -std=c99
-L/home/gert/mingw/lib -L/home/gert/mingw/opt/lib64 -lssl -lcrypto
-L/home/gert/mingw/opt/lib -llzo2 -L/home/gert/mingw/opt/lib -lcmocka
-L/home/gert/mingw/opt/lib -o example_testdriver.exe

example_testdriver-test.o
libtool: link: i686-w64-mingw32-gcc -I/home/gert/mingw/opt/include

(quoted diff) +0 -3
-I/home/gert/mingw/opt/include -I../../../include
-I/home/gert/mingw/opt/include -Wall -Wno-stringop-truncation
-I/home/gert/mingw/opt/include -std=c99 -o .libs/example_testdriver.exe

example_testdriver-test.o -L/home/gert/mingw/lib -L/home/gert/mingw/opt/lib64 -lssl -lcrypto -L/home/gert/mingw/opt/lib /home/gert/mingw/opt/lib/liblzo2.a -lwinmm -lcmocka /usr/bin/i686-w64-mingw32-ld:

Quoted 9 lines

example_testdriver-test.o:test.c:(.text+0x89): undefined reference to `_assert_int_equal'
/usr/bin/i686-w64-mingw32-ld:
example_testdriver-test.o:test.c:(.text+0xc6): undefined reference to `_assert_int_equal'
/usr/bin/i686-w64-mingw32-ld:
example_testdriver-test.o:test.c:(.text+0x153): undefined reference to `_cmocka_run_group_tests'

I had seen something similar with the master branch -- the def had some functions missing. But 1.1.5 worked out of the box.

Selva

#12 lore raw

Re: [Openvpn-devel] [PATCH v3 2/3] Build unit tests in mingw Windows build

Hi,

Quoted 6 lines · Selva Nair
Quoted 1 line · Gert Doering

/bin/bash ../../../libtool --tag=CC --mode=link i686-w64-mingw32-gcc

This is a 32 bit build which I never tried. Maybe cmocka is not built for 32 bit?

Yes, that was spot-on.

Found time to debug this with Arne today, and all the "non-cmocka" stuff was built with "configure --host=i686-w64-mingw32" while cmocka got "-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc", so the resulting .a library was full of 64 bit objects... which, of course, "file" doesn't tell on the .a, but unpacking libcmocka.dll.a + libcrypto.dll.a and looking at some of the contained .o told me...

[email protected]...:/tmp$ file cmocka_dll_d000001.o libcrypto_3_dll_d000001.o
cmocka_dll_d000001.o:      Intel amd64 COFF object file, no line number info, not stripped, 5 sections, symbol offset=0x138, 8 symbols, 1st section name ".text"
libcrypto_3_dll_d000001.o: Intel 80386 COFF object file, no line number info, not stripped, 5 sections, symbol offset=0x134, 9 symbols, 1st section name ".text"

... so, changed the cmocka CMAKE invocation to

    cmake -DCMAKE_SYSTEM_NAME=Windows \
            -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc \
            -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ \

...

rebuilt cmocka, and "make test" now does what we expect it to do - build something

[email protected]...:~/mingw/openvpn.git$ ls -l ./tests/unit_tests/openvpn/.libs
total 6504
-rwxrwxr-x 1 gert gert 541621 Feb 14 10:11 argv_testdriver.exe
-rw-rw-r-- 1 gert gert   6229 Feb 14 10:11 argv_testdriver_ltshwrapper
-rwxrwxr-x 1 gert gert 816794 Feb 14 10:12 auth_token_testdriver.exe
-rw-rw-r-- 1 gert gert   6248 Feb 14 10:12 auth_token_testdriver_ltshwrapper
-rwxrwxr-x 1 gert gert 536193 Feb 14 10:11 buffer_testdriver.exe
...

and not fail :-)

So, I can confirm that the yesterday-merged patch will make "make check" on a MinGW system do the right thing. I didn't test 64 bit compiles, as that wouldn't add insights on "it's make / configure specific" changes.

Thanks for your assistence and patience,

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#13 lore raw

[Openvpn-devel] [PATCH applied] Re: Build unit tests in mingw Windows build

In reply to [email protected]...

Tested on Linux (native), Linux / MinGW, AIX. Native platforms still run the tests (and succeed / fail as before).

On MinGW, if there is no cross-built libcmocka, this patch will not change anything. If there is, it tries to build the tests, which fails for me, but this seems to be a local install issue with cross-built cmocka and 32/64 bit compilers. It's not a problem introduced by this patch (the difference here is "do not *run* the resulting binaries") so I've decided to move forward with merging it.

Your patch has been applied to the master and release/2.6 branch.

commit e3ad1fc4230fb3a08b484e76ce0a31f2479d3c8f (master) commit a6d7e8843154bfca8b98a9eb11a11b320a03db36 (release/2.6)

Author: Selva Nair
Date:   Tue Feb 7 19:59:25 2023 -0500
     Build unit tests in mingw Windows build

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26188.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#14 lore raw

PATCH 3/5 Do not run check_engine test when crosscompiling

In reply to Arne Schwabe
---
 tests/unit_tests/engine-key/Makefile.am | 2 ++
 1 file changed, 2 insertions(+)
tests/unit_tests/engine-key/Makefile.am +2 -0
index 246222514..0c2888576 100644
@@ -12,7 +12,9 @@ TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
 	top_srcdir="$(top_srcdir)"; \
 	export srcdir builddir top_builddir top_srcdir;
 
+if !CROSS_COMPILING
 TESTS = check_engine_keys.sh
+endif
 check_engine_keys.sh: $(conffiles)
 
 CLEANFILES = \
Signature · 1 line
2.37.1 (Apple Git-137.1)
#15 lore raw

Re: [Openvpn-devel] [PATCH 3/5] Do not run check_engine test when crosscompiling

Hi,

Quoted 12 lines · Arne Schwabe
---
 tests/unit_tests/engine-key/Makefile.am | 2 ++
 1 file changed, 2 insertions(+)
tests/unit_tests/engine-key/Makefile.am +0 -0
index 246222514..0c2888576 100644

tests/unit_tests/engine-key/Makefile.am TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \ · line 20

Quoted 9 lines
tests/unit_tests/engine-key/Makefile.am +2 -0
@@ -12,7 +12,9 @@ TESTS_ENVIRONMENT = srcdir="$(abs_srcdir)"; \
        top_srcdir="$(top_srcdir)"; \
        export srcdir builddir top_builddir top_srcdir;
 
+if !CROSS_COMPILING
 TESTS = check_engine_keys.sh
+endif
 check_engine_keys.sh: $(conffiles)
 
 CLEANFILES = \

FTR, this patch is no longer needed (included in #2 below). So, the order of interdependent patches are: (All acked).

1. [Openvpn-devel,1/3] Conditionally add subdir-objects option to automake
<https://patchwork.openvpn.net/project/openvpn2/patch/[email protected].../>
2. [Openvpn-devel,v3,2/3] Build unit tests in mingw Windows build
<https://patchwork.openvpn.net/project/openvpn2/patch/[email protected].../>
3. [Openvpn-devel,4/5] Add missing stdint.h includes in unit tests files
<https://patchwork.openvpn.net/project/openvpn2/patch/[email protected].../>
4. [Openvpn-devel,v2,5/5] Add building unit tests with mingw to github actions
<https://patchwork.openvpn.net/project/openvpn2/patch/[email protected].../>

Selva

#16 lore raw

PATCH 4/5 Add missing stdint.h includes in unit tests files

In reply to Arne Schwabe

My mingw compiler/headers (mingw-w64 10.0.0 on macOS) seem to be more pendantic than the one that comes with Ubuntu 22.04 (github actions) or any of the other platforms including msvc/normal windows header.

---
 tests/unit_tests/example_test/test.c  | 1 +
 tests/unit_tests/example_test/test2.c | 1 +
 tests/unit_tests/openvpn/mock_msg.c   | 1 +
 3 files changed, 3 insertions(+)
tests/unit_tests/example_test/test.c +1 -0
index ea31b884d..c174025cc 100644
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <setjmp.h>
+#include <stdint.h>
 #include <cmocka.h>
 
 static int
tests/unit_tests/example_test/test2.c +1 -0
index 5a186d5d7..bb54633c8 100644
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <setjmp.h>
+#include <stdint.h>
 #include <cmocka.h>
 
 
tests/unit_tests/openvpn/mock_msg.c +1 -0
index 3ede98c00..3fa9a166f 100644
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <setjmp.h>
+#include <stdint.h>
 #include <cmocka.h>
 
 
Signature · 1 line
2.37.1 (Apple Git-137.1)

A message that is not in the archive (sent off-list or not yet received): [email protected]...

#18 lore raw

PATCH 4/5 Add missing stdint.h includes in unit tests files

CC list

---------- Forwarded message ---------
From: Selva Nair <[email protected]...>
Date: Wed, Feb 8, 2023 at 11:34 PM
Subject: Re: [Openvpn-devel] [PATCH 4/5] Add missing stdint.h includes in unit tests files
To: Arne Schwabe <[email protected]...>

Hi,

Quoted 43 lines · Arne Schwabe

My mingw compiler/headers (mingw-w64 10.0.0 on macOS) seem to be more pendantic than the one that comes with Ubuntu 22.04 (github actions) or any of the other platforms including msvc/normal windows header.

---
 tests/unit_tests/example_test/test.c  | 1 +
 tests/unit_tests/example_test/test2.c | 1 +
 tests/unit_tests/openvpn/mock_msg.c   | 1 +
 3 files changed, 3 insertions(+)
tests/unit_tests/example_test/test.c +1 -0
index ea31b884d..c174025cc 100644
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <setjmp.h>
+#include <stdint.h>
 #include <cmocka.h>
 
 static int
tests/unit_tests/example_test/test2.c +1 -0
index 5a186d5d7..bb54633c8 100644
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <setjmp.h>
+#include <stdint.h>
 #include <cmocka.h>
 
 
tests/unit_tests/openvpn/mock_msg.c +0 -0
index 3ede98c00..3fa9a166f 100644

tests/unit_tests/openvpn/mock_msg.c line 36

Quoted 5 lines
tests/unit_tests/openvpn/mock_msg.c +1 -0
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <setjmp.h>
+#include <stdint.h>
 #include <cmocka.h>

Actually it may not be your setup: mingw on Linux also requires this if using cmocka-master branch. cmocka-1.1.5 works without this include for me. That would explain why we haven't seen this error yet in native builds.

Anyway, cmocka docs also tell us to always include <stdint.h>.

#19 lore raw

[Openvpn-devel] [PATCH applied] Re: Add missing stdint.h includes in unit tests files

In reply to Arne Schwabe

Tested with cmocka on linux and AIX ("nothing more exotic than that").

Nothing breaks.

.. and if cmocka docs tell us "this is the thing", then it is :-)

Your patch has been applied to the master and release/2.6 branch.

commit e80720ef9399d7a4e3469cf1004d064643e0f4dd (master) commit 1b06696efb069ff9dfc77bac6cb487de232938cc (release/2.6)

Author: Arne Schwabe
Date:   Wed Feb 8 01:18:18 2023 +0100
     Add missing stdint.h includes in unit tests files

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Selva Nair <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26182.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#20 lore raw

PATCH 5/5 Add building and running mingw unittests to github actions

In reply to Arne Schwabe
---
 .github/workflows/build.yaml | 110 ++++++++++++++++++++++++++++++++++-
 1 file changed, 108 insertions(+), 2 deletions(-)
.github/workflows/build.yaml +108 -2
index 132624547..c71bd2c4d 100644
@@ -55,9 +55,10 @@ jobs:
       PKCS11_HELPER_VERSION: "1.29.0"
       OPENSSL_VERSION: "${{ matrix.osslver }}"
       TAP_WINDOWS_VERSION: "9.23.3"
+      CMOCKA_VERSION: "1.1.5"
     steps:
       - name: Install dependencies
-        run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip
+        run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip cmake ninja-build build-essential wget
       - name: Checkout OpenVPN
         uses: actions/[email protected]...
         with:
@@ -72,7 +73,7 @@ jobs:
         uses: actions/[email protected]...
         with:
           path: '~/mingw/'
-          key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{ env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{ env.TAP_WINDOWS_VERSION }}
+          key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{ env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{ env.TAP_WINDOWS_VERSION }}--${{ env.CMOCKA_VERSION }}
 
       # Repeating  if: steps.cache.outputs.cache-hit != 'true'
       # on every step for building dependencies is ugly but
@@ -84,12 +85,33 @@ jobs:
           wget -c -P download-cache/ "https://build.openvpn.net/downloads/releases/tap-windows-${TAP_WINDOWS_VERSION}.zip"
           wget -c -P download-cache/ "https://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz"
           wget -c -P download-cache/ "https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${PKCS11_HELPER_VERSION}/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
+          wget -c -P download-cache/ "https://github.com/coreboot/cmocka/archive/refs/tags/cmocka-${CMOCKA_VERSION}.tar.gz"
           tar jxf "download-cache/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
           wget -c -P download-cache/ "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz" || wget -c -P download-cache/ "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz"
           tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz"
           tar zxf "download-cache/lzo-${LZO_VERSION}.tar.gz"
+          tar zxf "download-cache/cmocka-${CMOCKA_VERSION}.tar.gz"
           unzip download-cache/tap-windows-${TAP_WINDOWS_VERSION}.zip
 
+      - name: create cmocka build directory
+        if: steps.cache.outputs.cache-hit != 'true'
+        run: mkdir cmocka-build
+
+      - name: configure cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: cmake -GNinja -DCMAKE_C_COMPILER=${{ matrix.chost }}-gcc -DCMAKE_CXX_COMPILER=${{ matrix.chost }}-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_PREFIX_PATH=${HOME}/mingw/opt/lib/pkgconfig/ -DCMAKE_INCLUDE_PATH=${HOME}/mingw/opt/lib/include -DCMAKE_LIBRARY_PATH=${HOME}/mingw/opt/lib -DCMAKE_INSTALL_PREFIX=${HOME}/mingw/opt/ ../cmocka-cmocka-${{ env.CMOCKA_VERSION }}
+
+      - name: build cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: ninja
+
+      - name: install cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: ninja install
+
       - name: Configure OpenSSL
         if: steps.cache.outputs.cache-hit != 'true'
         run: ./Configure --cross-compile-prefix=${{ matrix.chost }}- shared ${{ matrix.target }} no-capieng --prefix="${HOME}/mingw/opt" --openssldir="${HOME}/mingw/opt" -static-libgcc
@@ -154,6 +176,89 @@ jobs:
       - name: build OpenVPN
         run: make -j3
         working-directory: openvpn
+      - name: build OpenVPN unittests
+        run: make -j3 check
+        working-directory: openvpn
+
+      # We use multiple upload-artifact here, so it becomes a flat folder
+      # structure since we need the ddls on the same level as the binaries
+      - name: Archive cmocka/openssl/lzo ddls
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-dlls
+          path: '~/mingw/opt/bin/*.dll'
+
+      - name: Archive gcc dlls
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-dlls
+          path: /usr/lib/gcc/${{ matrix.chost }}/10-win32/*.dll
+
+      - name: Archive mingw dlls
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-dlls
+          path: /usr/${{ matrix.chost }}/lib/*.dll
+
+      # libtool puts some wrapper binaries in openvpn/tests/unit_tests/openvpn/
+      # and the real binaries in openvpn/tests/unit_tests/openvpn/.libs/
+      - name: Archive unittest artifacts
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
+          path: openvpn/tests/unit_tests/openvpn/.libs/*.exe
+
+      # Currently not used by the unit test but might in the future and also
+      # helpful if manually downloading and running openvpn.exe from a mingw
+      # build
+      - name: Archive openvpn binary
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
+          path: openvpn/src/openvpn/.libs/*.exe
+
+  mingw-unittest:
+    needs: [ mingw ]
+    strategy:
+      fail-fast: false
+      matrix:
+        osslver: [ 1.1.1q, 3.0.5 ]
+        target: [ mingw64, mingw ]
+
+    runs-on: windows-latest
+    name: "mingw unittests - ${{matrix.target}} - OSSL ${{ matrix.osslver }}"
+    steps:
+      - name: Retrieve mingw unittest dlls
+        uses: actions/[email protected]...
+        with:
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-dlls
+          path: unittests
+
+      - name: Retrieve mingw unittest
+        uses: actions/[email protected]...
+        with:
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
+          path: unittests
+
+      - name: List unittests directory
+        run: "dir unittests"
+
+      - name: Run unit tests
+        run: |
+          ./unittests/argv_testdriver.exe
+          ./unittests/auth_token_testdriver.exe
+          ./unittests/buffer_testdriver.exe
+          ./unittests/crypto_testdriver.exe
+          ./unittests/misc_testdriver.exe
+          ./unittests/ncp_testdriver.exe
+          ./unittests/packet_id_testdriver.exe
+          ./unittests/pkt_testdriver.exe
+          ./unittests/provider_testdriver.exe
 
   ubuntu:
     strategy:
@@ -442,3 +547,4 @@ jobs:
         run: make -j3
       - name: make check
         run: make check
+
Signature · 1 line
2.37.1 (Apple Git-137.1)
#21 lore raw

Re: [Openvpn-devel] [PATCH 5/5] Add building and running mingw unittests to github actions

Hi,

It's "absolutely splendid" to see cross-compiled tests running in GHA!

Some issues below:

Quoted 73 lines · Arne Schwabe
---
 .github/workflows/build.yaml | 110 ++++++++++++++++++++++++++++++++++-
 1 file changed, 108 insertions(+), 2 deletions(-)
.github/workflows/build.yaml +1 -1
index 132624547..c71bd2c4d 100644
@@ -55,9 +55,10 @@ jobs:
       PKCS11_HELPER_VERSION: "1.29.0"
       OPENSSL_VERSION: "${{ matrix.osslver }}"
       TAP_WINDOWS_VERSION: "9.23.3"
+      CMOCKA_VERSION: "1.1.5"
     steps:
       - name: Install dependencies
-        run: sudo apt update && sudo apt install -y mingw-w64 libtool

automake autoconf man2html unzip
+ run: sudo apt update && sudo apt install -y mingw-w64 libtool
automake autoconf man2html unzip cmake ninja-build build-essential wget
- name: Checkout OpenVPN
uses: actions/[email protected]...
with:

.github/workflows/build.yaml +1 -1
@@ -72,7 +73,7 @@ jobs:
         uses: actions/[email protected]...
         with:
           path: '~/mingw/'
-          key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{
 env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{
 env.TAP_WINDOWS_VERSION }}
+          key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{
 env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{

env.TAP_WINDOWS_VERSION }}--${{ env.CMOCKA_VERSION }}

# Repeating if: steps.cache.outputs.cache-hit != 'true' # on every step for building dependencies is ugly but

.github/workflows/build.yaml +0 -0
@@ -84,12 +85,33 @@ jobs:
           wget -c -P download-cache/ "

https://build.openvpn.net/downloads/releases/tap-windows-${TAP_WINDOWS_VERSION}.zip
"
wget -c -P download-cache/ "
https://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz
"
wget -c -P download-cache/ "
https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${PKCS11_HELPER_VERSION}/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2
"
+ wget -c -P download-cache/ "
https://github.com/coreboot/cmocka/archive/refs/tags/cmocka-${CMOCKA_VERSION}.tar.gz
"
tar jxf
"download-cache/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
wget -c -P download-cache/ "
https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz"
|| wget -c -P download-cache/ "
https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz"

           tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz"
           tar zxf "download-cache/lzo-${LZO_VERSION}.tar.gz"
.github/workflows/build.yaml +9 -5
+          tar zxf "download-cache/cmocka-${CMOCKA_VERSION}.tar.gz"
           unzip download-cache/tap-windows-${TAP_WINDOWS_VERSION}.zip
 
+      - name: create cmocka build directory
+        if: steps.cache.outputs.cache-hit != 'true'
+        run: mkdir cmocka-build
+
+      - name: configure cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: cmake -GNinja -DCMAKE_C_COMPILER=${{ matrix.chost }}-gcc
-DCMAKE_CXX_COMPILER=${{ matrix.chost }}-g++ -DCMAKE_SYSTEM_NAME=Windows
-DCMAKE_PREFIX_PATH=${HOME}/mingw/opt/lib/pkgconfig/
-DCMAKE_INCLUDE_PATH=${HOME}/mingw/opt/lib/include
-DCMAKE_LIBRARY_PATH=${HOME}/mingw/opt/lib
-DCMAKE_INSTALL_PREFIX=${HOME}/mingw/opt/ ../cmocka-cmocka-${{
Quoted 2 lines

env.CMOCKA_VERSION }}

Please add "-DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc" so that cmocka.dll will only depend on native Windows dlls. We already do this while building openssl dlls.

Quoted 17 lines
.github/workflows/build.yaml +11 -0
+
+      - name: build cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: ninja
+
+      - name: install cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: ninja install
+
       - name: Configure OpenSSL
         if: steps.cache.outputs.cache-hit != 'true'
         run: ./Configure --cross-compile-prefix=${{ matrix.chost }}-

shared ${{ matrix.target }} no-capieng --prefix="${HOME}/mingw/opt" --openssldir="${HOME}/mingw/opt" -static-libgcc

.github/workflows/build.yaml jobs: · line 185

Quoted 10 lines
.github/workflows/build.yaml +6 -0
@@ -154,6 +176,89 @@ jobs:
       - name: build OpenVPN
         run: make -j3
         working-directory: openvpn
+      - name: build OpenVPN unittests
+        run: make -j3 check
+        working-directory: openvpn
+
+      # We use multiple upload-artifact here, so it becomes a flat folder
+      # structure since we need the ddls on the same level as the binaries
 

ddls -> dlls

+ - name: Archive cmocka/openssl/lzo ddls

Quoted 5 lines
.github/workflows/build.yaml +4 -0
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

.github/workflows/build.yaml jobs: · line 197

Quoted 10 lines
.github/workflows/build.yaml +8 -0
 }}-dlls
+          path: '~/mingw/opt/bin/*.dll'
+
+      - name: Archive gcc dlls
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver
 }}-dlls
+          path: /usr/lib/gcc/${{ matrix.chost }}/10-win32/*.dll

This section ("Archive gcc dlls") is not required when mocka.dll is built with -static-libgcc as above. None of our exe's or dlls will have any dependency on these.

Quoted 9 lines
.github/workflows/build.yaml +6 -0
+
+      - name: Archive mingw dlls
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-dlls
+ path: /usr/${{ matrix.chost }}/lib/*.dll

Same with this "Archive mingw dlls" section

I tested these changes here:
https://github.com/selvanair/openvpn/tree/automake-cryptoapi

+

Quoted 68 lines

+ # libtool puts some wrapper binaries in
openvpn/tests/unit_tests/openvpn/

.github/workflows/build.yaml +6 -0
+      # and the real binaries in openvpn/tests/unit_tests/openvpn/.libs/
+      - name: Archive unittest artifacts
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-tests

.github/workflows/build.yaml +3 -0
+          path: openvpn/tests/unit_tests/openvpn/.libs/*.exe
+
+      # Currently not used by the unit test but might in the future and

also
+ # helpful if manually downloading and running openvpn.exe from a
mingw

.github/workflows/build.yaml +6 -0
+      # build
+      - name: Archive openvpn binary
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-tests

.github/workflows/build.yaml +12 -0
+          path: openvpn/src/openvpn/.libs/*.exe
+
+  mingw-unittest:
+    needs: [ mingw ]
+    strategy:
+      fail-fast: false
+      matrix:
+        osslver: [ 1.1.1q, 3.0.5 ]
+        target: [ mingw64, mingw ]
+
+    runs-on: windows-latest
+    name: "mingw unittests - ${{matrix.target}} - OSSL ${{ matrix.osslver

}}"

.github/workflows/build.yaml +5 -0
+    steps:
+      - name: Retrieve mingw unittest dlls
+        uses: actions/[email protected]...
+        with:
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-dlls

.github/workflows/build.yaml +6 -0
+          path: unittests
+
+      - name: Retrieve mingw unittest
+        uses: actions/[email protected]...
+        with:
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-tests

.github/workflows/build.yaml +16 -0
+          path: unittests
+
+      - name: List unittests directory
+        run: "dir unittests"
+
+      - name: Run unit tests
+        run: |
+          ./unittests/argv_testdriver.exe
+          ./unittests/auth_token_testdriver.exe
+          ./unittests/buffer_testdriver.exe
+          ./unittests/crypto_testdriver.exe
+          ./unittests/misc_testdriver.exe
+          ./unittests/ncp_testdriver.exe
+          ./unittests/packet_id_testdriver.exe
+          ./unittests/pkt_testdriver.exe
+          ./unittests/provider_testdriver.exe
 
   ubuntu:
     strategy:

.github/workflows/build.yaml jobs:

Quoted 5 lines
.github/workflows/build.yaml +1 -1
@@ -442,3 +547,4 @@ jobs:
         run: make -j3
       - name: make check
         run: make check
+
--

A couple of minor issues with the way test results are reported:

(1) The main name of the test being run is not printed

Normally when run from make check, we will get "PASSED pkt_testdriver" etc at the end which would be hard to recreate here. But we could add a line saying "Running pkt_testdriver" at the top. The individual tests within each exe are printed by cmocka, but unfortunately not all tests are carefully named to quickly see which group it belongs to.

(2) Messages like "Running 4 tests", "PASSED 4 tests" etc., appear out of order

Often "PASSED" appears before running tests or in the middle.

Eg.,
[==========] 9 test(s) run.
[ PASSED ] 11 test(s).
[ PASSED ] 7 test(s).
[==========] Running 11 test(s)

Then comes the description of those 11 tests.

Some tasks are running in parallel?

That said, reporting improvements could be done as a follow-up as this is already quite useful.

Regards,

Selva

#22 lore raw

PATCH v2 5/5 Add building unit tests with mingw to github actions

In reply to Arne Schwabe

This runs each test in its own action since order of stderr and stdout is seemingly random in github action Windows output and this way at least tests outputs are groups gy test

Patch v2: use -static-libgcc to avoid comping gcc runtime libraries.

---
 .github/workflows/build.yaml | 111 ++++++++++++++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 2 deletions(-)
.github/workflows/build.yaml +109 -2
index 5888e91e5..a1026fddb 100644
@@ -55,9 +55,10 @@ jobs:
       PKCS11_HELPER_VERSION: "1.29.0"
       OPENSSL_VERSION: "${{ matrix.osslver }}"
       TAP_WINDOWS_VERSION: "9.23.3"
+      CMOCKA_VERSION: "1.1.5"
     steps:
       - name: Install dependencies
-        run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip
+        run: sudo apt update && sudo apt install -y mingw-w64 libtool automake autoconf man2html unzip cmake ninja-build build-essential wget
       - name: Checkout OpenVPN
         uses: actions/[email protected]...
         with:
@@ -72,7 +73,7 @@ jobs:
         uses: actions/[email protected]...
         with:
           path: '~/mingw/'
-          key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{ env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{ env.TAP_WINDOWS_VERSION }}
+          key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{ env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{ env.TAP_WINDOWS_VERSION }}--${{ env.CMOCKA_VERSION }}
 
       # Repeating  if: steps.cache.outputs.cache-hit != 'true'
       # on every step for building dependencies is ugly but
@@ -84,12 +85,33 @@ jobs:
           wget -c -P download-cache/ "https://build.openvpn.net/downloads/releases/tap-windows-${TAP_WINDOWS_VERSION}.zip"
           wget -c -P download-cache/ "https://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz"
           wget -c -P download-cache/ "https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${PKCS11_HELPER_VERSION}/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
+          wget -c -P download-cache/ "https://github.com/coreboot/cmocka/archive/refs/tags/cmocka-${CMOCKA_VERSION}.tar.gz"
           tar jxf "download-cache/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
           wget -c -P download-cache/ "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz" || wget -c -P download-cache/ "https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz"
           tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz"
           tar zxf "download-cache/lzo-${LZO_VERSION}.tar.gz"
+          tar zxf "download-cache/cmocka-${CMOCKA_VERSION}.tar.gz"
           unzip download-cache/tap-windows-${TAP_WINDOWS_VERSION}.zip
 
+      - name: create cmocka build directory
+        if: steps.cache.outputs.cache-hit != 'true'
+        run: mkdir cmocka-build
+
+      - name: configure cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: cmake -GNinja -DCMAKE_C_COMPILER=${{ matrix.chost }}-gcc -DCMAKE_CXX_COMPILER=${{ matrix.chost }}-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc -DCMAKE_PREFIX_PATH=${HOME}/mingw/opt/lib/pkgconfig/ -DCMAKE_INCLUDE_PATH=${HOME}/mingw/opt/lib/include -DCMAKE_LIBRARY_PATH=${HOME}/mingw/opt/lib -DCMAKE_INSTALL_PREFIX=${HOME}/mingw/opt/ ../cmocka-cmocka-${{ env.CMOCKA_VERSION }}
+
+      - name: build cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: ninja
+
+      - name: install cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: ninja install
+
       - name: Configure OpenSSL
         if: steps.cache.outputs.cache-hit != 'true'
         run: ./Configure --cross-compile-prefix=${{ matrix.chost }}- shared ${{ matrix.target }} no-capieng --prefix="${HOME}/mingw/opt" --openssldir="${HOME}/mingw/opt" -static-libgcc
@@ -154,6 +176,90 @@ jobs:
       - name: build OpenVPN
         run: make -j3
         working-directory: openvpn
+      - name: build OpenVPN unittests
+        run: make -j3 check
+        working-directory: openvpn
+
+      # We use multiple upload-artifact here, so it becomes a flat folder
+      # structure since we need the dlls on the same level as the binaries
+      - name: Archive cmocka/openssl/lzo dlls
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-dlls
+          path: '~/mingw/opt/bin/*.dll'
+
+      # libtool puts some wrapper binaries in openvpn/tests/unit_tests/openvpn/
+      # and the real binaries in openvpn/tests/unit_tests/openvpn/.libs/
+      - name: Archive unittest artifacts
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
+          path: openvpn/tests/unit_tests/openvpn/.libs/*.exe
+
+      # Currently not used by the unit test but might in the future and also
+      # helpful if manually downloading and running openvpn.exe from a mingw
+      # build
+      - name: Archive openvpn binary
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
+          path: openvpn/src/openvpn/.libs/*.exe
+
+  mingw-unittest:
+    needs: [ mingw ]
+    strategy:
+      fail-fast: false
+      matrix:
+        osslver: [ 1.1.1q, 3.0.5 ]
+        target: [ mingw64, mingw ]
+
+    runs-on: windows-latest
+    name: "mingw unittests - ${{matrix.target}} - OSSL ${{ matrix.osslver }}"
+    steps:
+      - name: Retrieve mingw unittest dlls
+        uses: actions/[email protected]...
+        with:
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-dlls
+          path: unittests
+
+      - name: Retrieve mingw unittest
+        uses: actions/[email protected]...
+        with:
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver }}-tests
+          path: unittests
+
+      - name: List unittests directory
+        run: "dir unittests"
+
+      - name: Run argvunit test
+        run: ./unittests/argv_testdriver.exe
+
+      - name: Run auth_tokenunit test
+        run: ./unittests/auth_token_testdriver.exe
+
+      - name: Run bufferunit test
+        run: ./unittests/buffer_testdriver.exe
+
+      - name: Run cryptounit test
+        run: ./unittests/crypto_testdriver.exe
+
+      - name: Run miscunit test
+        run: ./unittests/misc_testdriver.exe
+
+      - name: Run ncpunit test
+        run: ./unittests/ncp_testdriver.exe
+
+      - name: Run packet idunit test
+        run: ./unittests/packet_id_testdriver.exe
+
+      - name: Run pktunit test
+        run: ./unittests/pkt_testdriver.exe
+
+      - name: Run providerunit test
+        run: ./unittests/provider_testdriver.exe
 
   ubuntu:
     strategy:
@@ -450,3 +556,4 @@ jobs:
         run: make -j3
       - name: make check
         run: make check
+
Signature · 1 line
2.37.1 (Apple Git-137.1)

A message that is not in the archive (sent off-list or not yet received): [email protected]...

#24 lore raw

PATCH v2 5/5 Add building unit tests with mingw to github actions

CC list was missed..

---------- Forwarded message ---------
From: Selva Nair <[email protected]...>
Date: Thu, Feb 9, 2023 at 2:54 PM
Subject: Re: [Openvpn-devel] [PATCH v2 5/5] Add building unit tests with mingw to github actions
To: Arne Schwabe <[email protected]...>

Hi,

Thanks, this is much better with tests grouped together.

Some nitpicks below that could be fixed while merging.

Quoted 4 lines · Arne Schwabe

This runs each test in its own action since order of stderr and stdout is seemingly random in github action Windows output and this way at least tests outputs are groups gy test

"test outputs are grouped by"

Quoted 161 lines

Patch v2: use -static-libgcc to avoid comping gcc runtime libraries.

---
 .github/workflows/build.yaml | 111 ++++++++++++++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 2 deletions(-)
.github/workflows/build.yaml +1 -1
index 5888e91e5..a1026fddb 100644
@@ -55,9 +55,10 @@ jobs:
       PKCS11_HELPER_VERSION: "1.29.0"
       OPENSSL_VERSION: "${{ matrix.osslver }}"
       TAP_WINDOWS_VERSION: "9.23.3"
+      CMOCKA_VERSION: "1.1.5"
     steps:
       - name: Install dependencies
-        run: sudo apt update && sudo apt install -y mingw-w64 libtool

automake autoconf man2html unzip
+ run: sudo apt update && sudo apt install -y mingw-w64 libtool
automake autoconf man2html unzip cmake ninja-build build-essential wget
- name: Checkout OpenVPN
uses: actions/[email protected]...
with:

.github/workflows/build.yaml +1 -1
@@ -72,7 +73,7 @@ jobs:
         uses: actions/[email protected]...
         with:
           path: '~/mingw/'
-          key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{
 env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{
 env.TAP_WINDOWS_VERSION }}
+          key: ${{ matrix.target }}-mingw-${{ matrix.osslver }}-${{
 env.LZO_VERSION }}-${{ env.PKCS11_HELPER_VERSION }}-${{

env.TAP_WINDOWS_VERSION }}--${{ env.CMOCKA_VERSION }}

# Repeating if: steps.cache.outputs.cache-hit != 'true' # on every step for building dependencies is ugly but

.github/workflows/build.yaml +0 -0
@@ -84,12 +85,33 @@ jobs:
           wget -c -P download-cache/ "

https://build.openvpn.net/downloads/releases/tap-windows-${TAP_WINDOWS_VERSION}.zip
"
wget -c -P download-cache/ "
https://www.oberhumer.com/opensource/lzo/download/lzo-${LZO_VERSION}.tar.gz
"
wget -c -P download-cache/ "
https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${PKCS11_HELPER_VERSION}/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2
"
+ wget -c -P download-cache/ "
https://github.com/coreboot/cmocka/archive/refs/tags/cmocka-${CMOCKA_VERSION}.tar.gz
"
tar jxf
"download-cache/pkcs11-helper-${PKCS11_HELPER_VERSION}.tar.bz2"
wget -c -P download-cache/ "
https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz"
|| wget -c -P download-cache/ "
https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz"

           tar zxf "download-cache/openssl-${OPENSSL_VERSION}.tar.gz"
           tar zxf "download-cache/lzo-${LZO_VERSION}.tar.gz"
.github/workflows/build.yaml +9 -6
+          tar zxf "download-cache/cmocka-${CMOCKA_VERSION}.tar.gz"
           unzip download-cache/tap-windows-${TAP_WINDOWS_VERSION}.zip
 
+      - name: create cmocka build directory
+        if: steps.cache.outputs.cache-hit != 'true'
+        run: mkdir cmocka-build
+
+      - name: configure cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: cmake -GNinja -DCMAKE_C_COMPILER=${{ matrix.chost }}-gcc
-DCMAKE_CXX_COMPILER=${{ matrix.chost }}-g++ -DCMAKE_SYSTEM_NAME=Windows
-DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc
-DCMAKE_PREFIX_PATH=${HOME}/mingw/opt/lib/pkgconfig/
-DCMAKE_INCLUDE_PATH=${HOME}/mingw/opt/lib/include
-DCMAKE_LIBRARY_PATH=${HOME}/mingw/opt/lib
-DCMAKE_INSTALL_PREFIX=${HOME}/mingw/opt/ ../cmocka-cmocka-${{

env.CMOCKA_VERSION }}

.github/workflows/build.yaml +11 -0
+
+      - name: build cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: ninja
+
+      - name: install cmocka
+        if: steps.cache.outputs.cache-hit != 'true'
+        working-directory: "./cmocka-build"
+        run: ninja install
+
       - name: Configure OpenSSL
         if: steps.cache.outputs.cache-hit != 'true'
         run: ./Configure --cross-compile-prefix=${{ matrix.chost }}-

shared ${{ matrix.target }} no-capieng --prefix="${HOME}/mingw/opt" --openssldir="${HOME}/mingw/opt" -static-libgcc

.github/workflows/build.yaml +14 -0
@@ -154,6 +176,90 @@ jobs:
       - name: build OpenVPN
         run: make -j3
         working-directory: openvpn
+      - name: build OpenVPN unittests
+        run: make -j3 check
+        working-directory: openvpn
+
+      # We use multiple upload-artifact here, so it becomes a flat folder
+      # structure since we need the dlls on the same level as the binaries
+      - name: Archive cmocka/openssl/lzo dlls
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver
 }}-dlls
+          path: '~/mingw/opt/bin/*.dll'
+
+      # libtool puts some wrapper binaries in

openvpn/tests/unit_tests/openvpn/

.github/workflows/build.yaml +6 -0
+      # and the real binaries in openvpn/tests/unit_tests/openvpn/.libs/
+      - name: Archive unittest artifacts
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-tests

.github/workflows/build.yaml +3 -0
+          path: openvpn/tests/unit_tests/openvpn/.libs/*.exe
+
+      # Currently not used by the unit test but might in the future and

also
+ # helpful if manually downloading and running openvpn.exe from a
mingw

.github/workflows/build.yaml +6 -0
+      # build
+      - name: Archive openvpn binary
+        uses: actions/[email protected]...
+        with:
+          retention-days: 1
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-tests

.github/workflows/build.yaml +12 -0
+          path: openvpn/src/openvpn/.libs/*.exe
+
+  mingw-unittest:
+    needs: [ mingw ]
+    strategy:
+      fail-fast: false
+      matrix:
+        osslver: [ 1.1.1q, 3.0.5 ]
+        target: [ mingw64, mingw ]
+
+    runs-on: windows-latest
+    name: "mingw unittests - ${{matrix.target}} - OSSL ${{ matrix.osslver

}}"

.github/workflows/build.yaml +5 -0
+    steps:
+      - name: Retrieve mingw unittest dlls
+        uses: actions/[email protected]...
+        with:
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-dlls

.github/workflows/build.yaml +6 -0
+          path: unittests
+
+      - name: Retrieve mingw unittest
+        uses: actions/[email protected]...
+        with:
+          name: mingw-unittest-${{matrix.target}}-ossl${{ matrix.osslver

}}-tests

.github/workflows/build.yaml jobs: · line 237

Quoted 6 lines
.github/workflows/build.yaml +6 -0
+          path: unittests
+
+      - name: List unittests directory
+        run: "dir unittests"
+
+      - name: Run argvunit test

"argvunit test" --> "argv unit test" etc. here and below ? This gets printed as the action name in output.

+ run: ./unittests/argv_testdriver.exe

.github/workflows/build.yaml

Quoted 2 lines
.github/workflows/build.yaml +2 -0
+
+      - name: Run auth_tokenunit test

+ run: ./unittests/auth_token_testdriver.exe

Quoted 25 lines
.github/workflows/build.yaml +21 -0
+
+      - name: Run bufferunit test
+        run: ./unittests/buffer_testdriver.exe
+
+      - name: Run cryptounit test
+        run: ./unittests/crypto_testdriver.exe
+
+      - name: Run miscunit test
+        run: ./unittests/misc_testdriver.exe
+
+      - name: Run ncpunit test
+        run: ./unittests/ncp_testdriver.exe
+
+      - name: Run packet idunit test
+        run: ./unittests/packet_id_testdriver.exe
+
+      - name: Run pktunit test
+        run: ./unittests/pkt_testdriver.exe
+
+      - name: Run providerunit test
+        run: ./unittests/provider_testdriver.exe
 
   ubuntu:
     strategy:

.github/workflows/build.yaml jobs: · line 559

Quoted 4 lines
.github/workflows/build.yaml +1 -0
@@ -450,3 +556,4 @@ jobs:
         run: make -j3
       - name: make check
         run: make check
+
#25 lore raw

[Openvpn-devel] [PATCH applied] Re: Add building unit tests with mingw to github actions

In reply to Arne Schwabe

Tested by pushing to my GH repo, and staring in amazement at the output.

Your patch has been applied to the master and release/2.6 branch.

commit 9719393b7cf94d37f3706ca32c02433e8578599b (master) commit adf00ebd51952554b02c6d8a5312b9b035b1f64c (HEAD -> release/2.6)

Author: Arne Schwabe
Date:   Thu Feb 9 17:37:05 2023 +0100
     Add building unit tests with mingw to github actions

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Selva Nair <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg26204.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering